/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.wallet.online.jwt;

import java.util.HashMap;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.wallet.online.jwt.util.GsonHelper;

/**
 * This class represents the TransactionStatusNotification JWT
 * 
 * The TransactionStatusNotification JWT is used to notify Payment Express of
 * the payment processing outcome. For example, if a CVC was incorrectly entered
 * it allows us to blow away their CVC data in Wallet.
 * 
 * @author pying(peng ying)
 * 
 */
public class TransactionStatusNotification extends JWTRequest {

  private final String TYPE = "google/wallet/online/transactionstatus/v2";
  private final String AUD = "Google";

  private TransactionStatusBody request;

  /**
   * This constructor should be used to define successful transaction
   * notifications
   * 
   * @param req
   */
  public TransactionStatusNotification(TransactionStatusBody req){
    setRequest(req);
    setType(TYPE);
    setAudience(AUD);
  }


  @Override
  public HashMap<String, JsonElement> getContent() {
    HashMap<String, JsonElement> content = new HashMap<String, JsonElement>();
    Gson gson = GsonHelper.getGson();
    JsonObject obj = gson.toJsonTree(getRequest()).getAsJsonObject();
    content.put("request", obj);
    return content;
  }

  public TransactionStatusBody getRequest() {
    return request;
  }

  public void setRequest(TransactionStatusBody request) {
    this.request = request;
  }
}
